package org.game.module.event.listener;

import java.util.List;

import org.bean.FriendInfo;
import org.constant.EventConditionKey;
import org.constant.EventConditionType;
import org.constant.EventType;
import org.constant.FriendConstant;
import org.game.db.bean.Player;
import org.game.plugin.event.GameEvent;
import org.game.plugin.event.GameEventListener;
import org.game.plugin.event.GameEventStack;
import org.game.plugin.event.GameEventType;
import org.utils.RemoteUtil;

import com.sojoys.artifact.tools.ToolMap;

/**
 * @author : DengYing
 * @CreateDate : 2018年1月16日 上午11:45:50
 * @Description ：Please describe this document
 */
@GameEventType(EventType.FRIEND)
public class FriendEventListenner implements GameEventListener {

	@Override
	public void onEvent(GameEvent event) {
		GameEventStack eventStack = event.peek();
		switch (eventStack.getConditionType()) {
			case EventConditionType.FRIEND_COUNT: {
				if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
					int changeFriendCount = ToolMap.getInt(EventConditionKey.CHANGE_FRIEND_COUNT, event.getIn());
					eventStack.changeProgress(changeFriendCount);
				}
				break;
			}
		}
	}

	@Override
	public void initEventCondition(Player player, GameEventStack eventStack) {
		switch (eventStack.getConditionType()) {
			case EventConditionType.FRIEND_COUNT: {
				List<FriendInfo> friends = RemoteUtil.socialSync().getFriends(player.getId());
				int count = 0;
				for (FriendInfo friendInfo : friends) {
					if (friendInfo.getStatus() == FriendConstant.STATUS_FRIEND) {
						count++;
					}
				}
				eventStack.setProgress(count);
				break;
			}
		}
	}

}
